package lu.med.praxiswahl.wahlumed.client.lieferanten;

import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.TableColumn;
import lu.med.praxiswahl.wahlumed.client.utilities.ColumnWidthControler;
import lu.med.praxiswahl.wahlumed.client.wclient.Main;

/**
 * 
 * @author Lars Holger Roth
 */
@SuppressWarnings("serial")
public class LieferantenTable extends JTable {

	private ColumnWidthControler c;
	private boolean isColumnWidthChanged;
	private TableColumn resizedColumn;

	public LieferantenTable(LieferantenTableModel model) {
		super(model);
		this.setRowHeight(30);
		// TableRowSorter<LieferantenTableModel> rowSorter = new
		// TableRowSorter<LieferantenTableModel>();
		// this.setRowSorter(rowSorter);
		// rowSorter.setModel(model);
		// LieferantenTableStringConverter strComp = new
		// LieferantenTableStringConverter();
		// rowSorter.setStringConverter(strComp);
		this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		this.selectionModel = getSelectionModel();
		this.selectionModel
				.addListSelectionListener(new LieferantenTableSelectionListener(
						model));
		this.setDefaultRenderer(Object.class,
				new LieferantenCellRenderer(model));
		this.setDefaultEditor(Object.class, new LieferantenCellEditor(model));

		TableColumn column = null;

		c = new ColumnWidthControler(Main.COLUMNWIDTH_CONFIGURATION_FILE,
				"lieferanttbl", this);

		for (int i = 0; i < 13; i++) {
			column = this.getColumnModel().getColumn(i);
			column.setPreferredWidth(c.getColumnWidth(i));
		}

		this.getColumnModel().addColumnModelListener(
				new TableColumnWidthListener(this));
		this.getTableHeader().addMouseListener(
				new TableHeaderMouseListener(this, c));

	}

	public boolean getColumnWidthChanged() {
		return isColumnWidthChanged;
	}

	public void setColumnWidthChanged(boolean widthChanged,
			TableColumn resizedColumn) {
		isColumnWidthChanged = widthChanged;
		this.resizedColumn = resizedColumn;
	}

	public TableColumn getResizedColumn() {
		return resizedColumn;
	}

}
